// CSE 142, Winter 2008, Marty Stepp // // This program randomly rolls two 6-sided dice until // it rolls a lucky 7. import java.util.*; public class Dice { public static void main(String[] args) { Random randy = new Random(); int d1 = 0; // "dummy" values, anything that doesn't add to 7 int d2 = 0; int count = 0; // how many times we have rolled while (d1 + d2 != 7) { // roll the dice d1 = randy.nextInt(6) + 1; d2 = randy.nextInt(6) + 1; System.out.println(d1 + " + " + d2 + " = " + (d1 + d2)); count++; } System.out.println("You won after " + count + " tries!"); } }